<template>
  <div class='home'>
    <van-swipe
      class="my-swipe"
      :autoplay="3000"
      indicator-color="white"
    >
      <van-swipe-item
        v-for="item in lunbolist"
        :key="item.id"
      >
        <img
          :src="item.img"
          alt=""
        >
      </van-swipe-item>
    </van-swipe>

    <van-grid :column-num="3">
      <van-grid-item
        v-for="grid in grids"
        :key="grid.id"
        :icon="grid.src"
        :text="grid.title"
      />
    </van-grid>
  </div>
</template>
<script>
import axios from 'axios'
export default {
  data: () => ({
    lunbolist: [],
    grids: []
  }),
  //created是初始化函数，放外面不是放方法里面
  created() {
    this.getlunbo();
    this.getgrids();
  },
  methods: {
    async getlunbo() {
      // console.log("22222222222");
      let res = await axios.get("http://itfly.vip:8888/api/getlunbo")
      console.log(res);
      this.lunbolist = res.data.message;
    },
    async getgrids() {
      // console.log("22222222222");
      let res = await axios.get("http://itfly.vip:8888/api/grids")
      console.log(res);
      this.grids = res.data.message;
    }
  }
}
</script>
<style lang="scss">
.home {
  .my-swipe {
    height: 200px;
    background: pink;
    img {
      //设置图片占据父容器的百分之百
      width: 100%;
      height: 100%;
    }
  }
  // 要放开scope才能渗透 这是第三方组件的类
  .van-grid-item__icon {
    font-size: 60px;
  }
}
</style>